//
//  GSArticleView.m
//  GameSky
//
//  Created by lanou on 16/1/14.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSArticleView.h"

#define kButtonWidth 30
#define kMargin (kScreenWidth - kButtonWidth * 5 - 60) / 7

@implementation GSArticleView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        // 1.添加导航栏;
        _navBar = [[GSCustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, kWidth, 64)];
        [self addSubview:_navBar];
        // 左边按钮
        [_navBar.leftButton setImage:[UIImage imageNamed:@"common_Icon_Back_20x20_UIMode_Day"] forState:(UIControlStateNormal)];
        // 右边按钮
        [_navBar.rightButton setImage:[UIImage imageNamed:@"common_Icon_More_20x20_UIMode_Day"] forState:(UIControlStateNormal)];
        
        // 2.添加工具栏;
        UIView *toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - 40, kWidth, 40)];
        toolBar.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        [self addSubview:toolBar];
        
        // 上一页按钮
        _lastPageBtn = [[GSBorderButton alloc] initWithFrame:CGRectMake(kMargin, 5, kButtonWidth, kButtonWidth)];
        [_lastPageBtn setImage:[UIImage imageNamed:@"common_Icon_Back_26x26_UIMode_Day"] forState:(UIControlStateNormal)];
        [toolBar addSubview:_lastPageBtn];
        
        // 当前页按钮
        _currentPageBtn = [[GSBorderButton alloc] initWithFrame:CGRectMake(self.lastPageBtn.right + kMargin, 5, 60, kButtonWidth)];
        [_currentPageBtn setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [toolBar addSubview:_currentPageBtn];
        
        // 下一页按钮
        _nextPageBtn = [[GSBorderButton alloc] initWithFrame:CGRectMake(self.currentPageBtn.right + kMargin, 5, kButtonWidth, kButtonWidth)];
        [_nextPageBtn setImage:[UIImage imageNamed:@"common_Icon_Forward_26x26_UIMode_Day"] forState:(UIControlStateNormal)];
        [toolBar addSubview:_nextPageBtn];
        
        // 喜欢按钮
        _shareBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.nextPageBtn.right + kMargin, 5, kButtonWidth, kButtonWidth)];
        [_shareBtn setImage:[UIImage imageNamed:@"common_Icon_ShareOrFavorite_26x26_UIMode_Day"] forState:(UIControlStateNormal)];
        [_shareBtn setImage:[UIImage imageNamed:@"common_Icon_ShareOrFavoriteSelected_26x26_UIMode_Day"] forState:(UIControlStateSelected)];
        [toolBar addSubview:_shareBtn];
        
        // 评论按钮
        _commentBtn = [[GSCommentButton alloc] initWithFrame:CGRectMake(self.shareBtn.right + kMargin, 5, kButtonWidth, kButtonWidth)];
        [_commentBtn setImage:[UIImage imageNamed:@"common_Icon_NewComment_26x26_UIMode_Day"] forState:(UIControlStateNormal)];
        [_commentBtn addTarget:self action:@selector(commentBtnClick:) forControlEvents:(UIControlEventTouchUpInside)];
        [toolBar addSubview:_commentBtn];
        
        // 评论界面按钮
        _commentUIBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.commentBtn.right + kMargin, 5, kButtonWidth, kButtonWidth)];
        [_commentUIBtn setImage:[UIImage imageNamed:@"common_Icon_Comments_26x26_UIMode_Day"] forState:(UIControlStateNormal)];
        [toolBar addSubview:_commentUIBtn];
        
        // 评论数标签
        _commentLabel = [[UILabel alloc] init];
        _commentLabel.center = CGPointMake(_commentUIBtn.center.x, _commentUIBtn.center.y - 2);
        _commentLabel.bounds = CGRectMake(0, 0, 15, 15);
        _commentLabel.font = [UIFont systemFontOfSize:10];
        _commentLabel.textColor = [UIColor whiteColor];
        _commentLabel.textAlignment = NSTextAlignmentCenter;
        _commentLabel.userInteractionEnabled = YES;
        [toolBar addSubview:_commentLabel];
    }
    return self;
}
// 评论按钮点击方法;
- (void)commentBtnClick:(GSCommentButton *)button
{
    [button becomeFirstResponder];    
}

- (void)setModel:(GSNewsArticleModel *)model
{
    _model = model;
    [_currentPageBtn setTitle:[NSString stringWithFormat:@"1/%@",model.pageCount] forState:(UIControlStateNormal)];
    _commentLabel.text = [NSString stringWithFormat:@"%@",model.adId];
}

@end
